<?php
/*支付页面 
* @Author: Jerry-chen
* @Date:   2014-07-21 17:28:16
* @Last Modified time: 2014-07-23 17:09:07
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/

class PayControl extends CommonControl
{
	
	public function index()
	{
		// 先把名字和邮箱地址插入订单 
		// 1为电子票
		if($_POST['spstatu']==0&& $_SESSION['step']==3){
			$data = array(
			'name'=>$_POST['name0'],
			'email'=>$_POST['email0'],
			'spstatu'=>$_POST['spstatu']
			);
			
		}elseif($_POST['spstatu']==2){
			$data = array(
			'name'=>$_POST['name2'],
			'email'=>$_POST['email2'],
			'spstatu'=>$_POST['spstatu']
			);
			K('Order')->edit(array('orderid'=>Q('post.orderid')),$data);
			session('step',4);
		}
		// p($_POST);
		//订单相关
		//根据订单号查出同一订单的商品，然后分配数据
			$orderdata = K('Order')->get_all(array('uid'=>session('uid'),'orderid'=>Q('post.orderid')));
			// p($orderdata);
			$count = 0;
			foreach ($orderdata as $k => $v) {
				$orderlist = K('Orderlist')->get_all(array('orderid'=>$v['orderid']),array('timeid','goodsid','price','number','recount'));
				// p($orderlist);

				$orderdata[$k]['orderlist'] = $orderlist;
					foreach ($orderlist as $key => $value) {
						// 根据时间ID，查出时间
					$timename = K('Goodstime')->get_one(array('timeid'=>$value['timeid']),array('time'));
					$orderdata[$k]['orderlist'][$key]['time'] = $timename['time'];
					//根据货品ID查出货物名
					$goodsname = K('Goods')->get_one(array('goodsid'=>$value['goodsid']),array('goodsname'));
					$orderdata[$k]['orderlist'][$key]['goodsname'] = $goodsname['goodsname'];
					//价格
					$orderdata[$k]['orderlist'][$key]['price'] = $value['price'];
					$orderdata[$k]['orderlist'][$key]['number'] = $value['number'];
					$orderdata[$k]['orderlist'][$key]['recount'] = $value['recount'];
					$count += $value['recount'];
					//订单合计
					}
				$orderdata[$k]['paynumber'] = time();
				$orderdata[$k]['goodsname'] = $goodsname['goodsname'];
					
			}
			//分配订单数据
			$this->assign('orderdata',$orderdata);
			$this->assign('count',$count);
			// p($orderdata);
			$this->display('pay.html');
	}
	/**
	 * [pay_ok 付款成功]
	 * @return [type] [description]
	 */
	public function pay_ok()
	{
		// stadus = 1
		 $orderdata = K('Order')->get_one(array('orderid'=>Q('get.orderid'))); 
		$tickpassword = md5($orderdata['ordernumber']);
		$data =array(
			'stadus'=>1,
			'tickpassword'=>$tickpassword,
			);
		$result = K('Order')->edit(array('orderid'=>Q('get.orderid')),$data);
		
		if($result)
		{
			session('step','4');
			$this->success('付款成功',U('Index/index'));
		}
	}
}